package ru.alperez.util;

import android.content.Context;
import android.os.Build;
import android.telephony.TelephonyManager;
import ru.alperez.model.Creator;

public class CreatorManager {
	private static final CreatorManager instance = new CreatorManager();
	
	private Creator creator;
	
	private CreatorManager() {
	}
	
	
	public static CreatorManager getInstance() {
		return instance;
	}
	
	public void initialize(Context context, String name, String description) {
		if (name==null || name.length()==0) return;
		creator = new Creator();
		creator.setName(new String(name));
		creator.setDescription(new String(description));
		creator.setDevice(Build.DEVICE);
		creator.setModel(Build.MODEL);
		creator.setImei(((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId());		
	}
	
	public Creator getCreator() throws CreatorManagerNoInitException {
		if (creator == null) throw new CreatorManagerNoInitException("you must call initialize() method for CreatorManager first");
		return creator;
	}
	
	public boolean isInit() {
		return (creator != null);
	}
}
